﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using XLSupermarket.Storehouse.Commodity_Stocks;
using Supermarket;
using System.IO;

namespace XLSupermarket.Storehouse
{
    public partial class Storehouse : Form
    {
        public Storehouse()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //跳转到商品入库界面
            Commodity_warehousing.Commodity_warehousing CW = new Commodity_warehousing.Commodity_warehousing();
            CW.ShowDialog();
        }
        private void button8_Click(object sender, EventArgs e)
        {
            //仓库退出功能
            DialogResult result = MessageBox.Show("您确认退出吗？", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (result == DialogResult.OK) System.Environment.Exit(0);
        }
        private void button4_Click(object sender, EventArgs e)
        {
            //跳转到商品库存界面
            Commodity_Stocks.Commodity_Stocks CS = new Commodity_Stocks.Commodity_Stocks();
            CS.ShowDialog();
        }
        private void button3_Click(object sender, EventArgs e)
        {
            //跳转到商品出库界面
            Commodity_Delivery.Commodity_Delivery CD = new Commodity_Delivery.Commodity_Delivery();
            CD.ShowDialog();
        }
        private void button9_Click(object sender, EventArgs e)
        {
            //返回系统主界面
            MainInterface.MainForm MF = new MainInterface.MainForm();
            this.Hide();
            MF.Show();

        }
        private void button1_Click(object sender, EventArgs e)
        {
            //注销回到登录界面
            LoginForm loginForm = new LoginForm();
            DialogResult result = MessageBox.Show("你确定要返回吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (result == DialogResult.Yes)
            {
                this.Hide();
                loginForm.Show();
            }
        }
        private void Storehouse_Load(object sender, EventArgs e)
        {
            try { 
            //头像返回到仓库界面
            string userName = LoginForm.UserName_Value;//账号
            string sql = "select Src from EP_Number where UserName='" + userName + "'";
            DataTable sdr = DBHelper.FillData(sql);
            string path = sdr.Rows[0]["Src"].ToString();
            FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
            Image img = Image.FromStream(fs);
            PB_Photo.Image = img;
            //返回姓名
            string sql1 = "select EP_Name from EP_Number en,EP_information ei where en.EP_ID = ei.EP_ID and en.UserName = '" + userName + "'";
            DataTable sdr1 = DBHelper.FillData(sql1);
            string name = sdr1.Rows[0][0].ToString();
            this.label2.Text = name;
            //只有店长可以返回主界面
            string sql3 = "select Staff_Name from EP_Number en,EP_information ei where en.EP_ID = ei.EP_ID and en.UserName = '" + userName + "'";
            DataTable sdr3 = DBHelper.FillData(sql3);
            if (sdr3.Rows[0][0].ToString() == "店长")
            {
                this.button9.Show();
            }
            else
            {
                this.button9.Hide();
            }
            //获取从主页面获取的员工姓名
            sql1 = "select EP_Name from EP_Number en,EP_information ei where en.EP_ID = ei.EP_ID and en.UserName = '" + userName + "'";
            sdr1 = DBHelper.FillData(sql1);
            name = sdr1.Rows[0][0].ToString();
            this.label3.Text = name;
            }
            catch (Exception ex)
            {
                MessageBox.Show("出现错误：" + ex.Message);
            }
        }
        /// <summary>
        /// 商品类型
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button5_Click(object sender, EventArgs e)
        {
            Commodity_Type.Commodity_Type CTCT = new Commodity_Type.Commodity_Type();
            CTCT.ShowDialog();
        }
        /// <summary>
        /// 供货商信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button6_Click(object sender, EventArgs e)
        {
            Supplier_Information.Supplier_Information SISI = new Supplier_Information.Supplier_Information();
            SISI.ShowDialog();
        }
        private void button7_Click(object sender, EventArgs e)
        {
            panel4.Show();
            button2.Hide();
            button3.Hide();
            button4.Hide();
            button7.Hide();
            button12.Show();
        }
        private void button12_Click(object sender, EventArgs e)
        {
            panel4.Hide();
            button2.Show();
            button3.Show();
            button4.Show();
            button7.Show();
            button12.Hide();
        }
        private void button13_Click(object sender, EventArgs e)
        {
            Account.ChangePassword.UpPwd ACP = new Account.ChangePassword.UpPwd();
            ACP.ShowDialog();
        }
        private void button7_Click_1(object sender, EventArgs e)
        {
            Account.Information.seletInformationForm AIS = new Account.Information.seletInformationForm();
            AIS.ShowDialog();
        }
    }
}
